//
//listTableView
//listArray
//lotIDImageDic
//  AnnouncementViewController.m
//  CaiPiao
//
//  Created by apple on 2018/5/15.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "AnnouncementViewController.h"
#import "AnnouncementTableViewCell.h"

@interface AnnouncementViewController ()

@property (weak, nonatomic) IBOutlet UITableView *listTableView;
@property (nonatomic,retain)NSArray* listArray;

@end

@implementation AnnouncementViewController{
    NSDictionary* lotIDImageDic;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"开奖";
    [EasyLodingView showLodingText:@"正在努力加载中..." config:^EasyLodingConfig *{
        return [EasyLodingConfig shared].setLodingType(LodingShowTypeIndicator);
    }];
    
    lotIDImageDic = @{
                      @(9):@"ks",
                      @(5):@"福彩3D",
                      @(1):@"竞彩足球",
                      @(14):@"江苏11选5",
                      @(6):@"排列三",
                      @(2):@"竞彩篮球",
                      @(11):@"胜负彩",
                      @(7):@"11x5",
                      @(3):@"双色球",
                      @(8):@"夺金11选5",
                      @(4):@"大乐透"
    };
    [self.listTableView registerNib:[UINib nibWithNibName:@"AnnouncementTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"AnnouncementTableViewCell"];
    __weak typeof(self)weakSelf = self;
    [[LotteryManager sharedManager] getLotteryListActionWithCallBack:^(BOOL load, NSDictionary *resObj) {
        if (load) {
            if ([resObj[@"code"] integerValue]==0) {
                weakSelf.listArray = resObj[@"data"];
                [weakSelf reloadAction];
            }
        }
    }];
    
    
}

-(void)reloadAction{
    [EasyLodingView hidenLoding];
    [self.listTableView reloadData];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self.listArray count];
}

//EndTime = "2018/05/15";
//HTeam = "";
//ID = 774132;
//IssueName = 2018055;
//LotteryID = 3;
//LotteryName = "\\U53cc\\U8272\\U7403";
//QuickFlag = 0;
//RValue = "";
//Rz = "07 09 10 12 22 26+07";
//VTeam = "";
//WinNumber = "07 09 10 12 22 26+07";


//EndTime = "2018/05/16";
//HTeam = "\\U79d1\\U6d1b\\U79d1\\U6d1b";
//ID = 955299;
//IssueName = 20180515;
//LotteryID = 1;
//LotteryName = "\\U7ade\\U5f69\\U8db3\\U7403";
//QuickFlag = 0;
//RValue = "-1";
//Rz = "2:0";
//VTeam = "\\U73bb\\U5229\\U74e6\\U5c14";
//WinNumber = "";

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    AnnouncementTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"AnnouncementTableViewCell"];
    NSDictionary* dic=self.listArray[indexPath.row];
    cell.titleLabel.text = dic[@"LotteryName"];
    cell.dateLabel.text = [NSString stringWithFormat:@"%@期 %@",dic[@"IssueName"],[dic[@"EndTime"] stringByReplacingOccurrencesOfString:@"/" withString:@"-"]];
    NSString* imageKey = dic[@"LotteryID"];
    cell.titleImageView.image = [UIImage imageNamed:lotIDImageDic[imageKey]];
    if ([dic[@"WinNumber"] length]>0) {
        [cell setWinNumWith:dic[@"WinNumber"]];
    }else{
        [cell setTeamWith:dic];
    }
    return cell;
}

//numberSegue
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary* dic=self.listArray[indexPath.row];
    [LotteryManager sharedManager].currentLotteryID = dic[@"LotteryID"];
    [LotteryManager sharedManager].currentLotteryName = dic[@"LotteryName"];
    if ([dic[@"WinNumber"] length]>0) {
        [self performSegueWithIdentifier:@"numberSegue" sender:nil];
    }else{
        [self performSegueWithIdentifier:@"SMGSegue" sender:nil];
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
